package com.yogee.topseller.fragment.zhoubian;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.core.base.HttpFragment;
import com.yogee.core.base.HttpFragment1;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.XzcfActivity;
import com.yogee.topseller.activity.ZhoubianActivity;
import com.yogee.topseller.activity.tianyan.BzxrDetailActivity;
import com.yogee.topseller.activity.tianyan.GphqDetailActivity;
import com.yogee.topseller.activity.tianyan.GqczDetailActivity;
import com.yogee.topseller.activity.tianyan.QyfxActivity;
import com.yogee.topseller.adapter.FengxianAdapter;
import com.yogee.topseller.bean.BzxrBean;
import com.yogee.topseller.bean.DcdyBean;
import com.yogee.topseller.bean.FengxianBean;
import com.yogee.topseller.bean.GbbdBean;
import com.yogee.topseller.bean.GbjgBean;
import com.yogee.topseller.bean.GpfhBean;
import com.yogee.topseller.bean.GphqBean;
import com.yogee.topseller.bean.GqczBean;
import com.yogee.topseller.bean.GrfxBean;
import com.yogee.topseller.bean.InterlligentFilterBean;
import com.yogee.topseller.bean.JigouBean;
import com.yogee.topseller.bean.JyycBean;
import com.yogee.topseller.bean.QyfxBean;
import com.yogee.topseller.bean.ResultBean1;
import com.yogee.topseller.bean.SxrBean;
import com.yogee.topseller.bean.XzcfBean;
import com.yogee.topseller.bean.YzwfBean;
import com.yogee.topseller.bean.ZhoubianBean;
import com.yogee.topseller.bean.ZqxxBean;
import com.yogee.topseller.fragment.collect.CollectBodyFragment;
import com.yogee.topseller.fragment.productdetail.BaseFragment;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.Constants;
import com.yogee.topseller.utils.LogUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class FengxianFragment1 extends HttpFragment implements ZhoubianActivity.UpdateListener{
    @BindView(R.id.ll_item1)
    LinearLayout ll_item1;
    @BindView(R.id.ll_item2)
    LinearLayout ll_item2;
    @BindView(R.id.ll_item3)
    LinearLayout ll_item3;
    @BindView(R.id.ll_item4)
    LinearLayout ll_item4;
    @BindView(R.id.ll_item5)
    LinearLayout ll_item5;
    @BindView(R.id.ll_item6)
    LinearLayout ll_item6;
    @BindView(R.id.ll_item7)
    LinearLayout ll_item7;
    @BindView(R.id.ll_item8)
    LinearLayout ll_item8;
    @BindView(R.id.ll_item9)
    LinearLayout ll_item9;
    @BindView(R.id.ll_item10)
    LinearLayout ll_item10;
    @BindView(R.id.ll_item11)
    LinearLayout ll_item11;
    @BindView(R.id.ll_item12)
    LinearLayout ll_item12;
    @BindView(R.id.ll_item13)
    LinearLayout ll_item13;
    @BindView(R.id.ll_item14)
    LinearLayout ll_item14;
    @BindView(R.id.ll_item15)
    LinearLayout ll_item15;
    @BindView(R.id.tv_1)
    TextView tv_1;
    @BindView(R.id.tv_2)
    TextView tv_2;
    @BindView(R.id.tv_3)
    TextView tv_3;
    @BindView(R.id.tv_4)
    TextView tv_4;
    @BindView(R.id.tv_5)
    TextView tv_5;
    @BindView(R.id.tv_6)
    TextView tv_6;
    @BindView(R.id.tv_7)
    TextView tv_7;
    @BindView(R.id.tv_8)
    TextView tv_8;
    @BindView(R.id.tv_9)
    TextView tv_9;
    @BindView(R.id.tv_10)
    TextView tv_10;
    @BindView(R.id.tv_11)
    TextView tv_11;
    @BindView(R.id.tv_12)
    TextView tv_12;
    @BindView(R.id.tv_13)
    TextView tv_13;
    @BindView(R.id.tv_14)
    TextView tv_14;
    @BindView(R.id.tv_15)
    TextView tv_15;

    Unbinder unbinder1;
    private int isMj = 0;
    ZhoubianBean bean;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_fengxian1;
    }


    @Override
    protected void initView() {
        ((ZhoubianActivity)getActivity()).setListener1(this);
        JigouBean.Company company =((ZhoubianActivity)getActivity()).getMySelectCompany();
        if(company!=null)
            eyeCheckCount(AppUtil.getUserId(getActivity()),company.getId());
        else{
            bean = null;
            showview(new ZhoubianBean());
        }
    }

    private void eyeCheckCount(String userId, String relatedCompanyId) {
        if(!TextUtils.isEmpty(relatedCompanyId)){
            if(pd!=null)
                pd.show();
            HttpManager.getInstance().eyeCheckCount(relatedCompanyId, userId)
                    .compose(bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<ZhoubianBean>() {
                @Override
                public void onNext(ZhoubianBean o) {
                    if(pd!=null)
                        pd.dismiss();
                    bean = o;
                    showview(o);
                }
            }, this));
        }
    }

    @Override
    public void showMsg(String msg) {
        super.showMsg(msg);
        if(pd!=null)
            pd.dismiss();
    }

    private  void showview(ZhoubianBean zhoubianBean){
        try{
            if(zhoubianBean==null){
                tv_1.setVisibility(View.GONE);
                tv_2.setVisibility(View.GONE);
                tv_3.setVisibility(View.GONE);
                tv_4.setVisibility(View.GONE);
                tv_6.setVisibility(View.GONE);
                tv_7.setVisibility(View.GONE);
                tv_8.setVisibility(View.GONE);
                tv_9.setVisibility(View.GONE);
                tv_10.setVisibility(View.GONE);
                tv_12.setVisibility(View.GONE);
                tv_14.setVisibility(View.GONE);
                tv_15.setVisibility(View.GONE);
            }else{
                // 行政处罚
                if("0".equals(zhoubianBean.getXzrf())||"".equals(zhoubianBean.getXzrf())){
                    tv_1.setVisibility(View.GONE);
                }else{
                    if(zhoubianBean.getXzrf().length()>2){
                        tv_1.setText("···");
                    }else
                        tv_1.setText(zhoubianBean.getXzrf());
                    tv_1.setVisibility(View.VISIBLE);

                }
                // 严重违法
                if("0".equals(zhoubianBean.getYzwf())||"".equals(zhoubianBean.getYzwf())){
                    tv_2.setVisibility(View.GONE);
                }else{
                    if(zhoubianBean.getYzwf().length()>2){
                        tv_2.setText("···");
                    }else
                        tv_2.setText(zhoubianBean.getXzrf());
                    tv_2.setText(zhoubianBean.getYzwf());
                }
                // 股权出质
                if("0".equals(zhoubianBean.getGqcz())||"".equals(zhoubianBean.getGqcz())){
                    tv_3.setVisibility(View.GONE);
                }else{
                        if(zhoubianBean.getGqcz().length()>2){
                            tv_3.setText("···");
                    }else
                        tv_3.setText(zhoubianBean.getGqcz());
                    tv_3.setVisibility(View.VISIBLE);
                }
                // 股本变动
                if("0".equals(zhoubianBean.getGbbd())||"".equals(zhoubianBean.getGqcz())){
                    tv_4.setVisibility(View.GONE);
                }else{
                    if(zhoubianBean.getGbbd().length()>2){
                        tv_4.setText("···");
                    }else
                        tv_4.setText(zhoubianBean.getGbbd());
                    tv_4.setVisibility(View.VISIBLE);
                }
                // 经营异常
                if("0".equals(zhoubianBean.getJyrc())||"".equals(zhoubianBean.getJyrc())){
                    tv_6.setVisibility(View.GONE);
                }else{
                    tv_6.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getJyrc().length()>2){
                        tv_6.setText("···");
                    }else
                        tv_6.setText(zhoubianBean.getJyrc());
                }
                // 动产抵押
                if("0".equals(zhoubianBean.getDcdy())||"".equals(zhoubianBean.getDcdy())){
                    tv_7.setVisibility(View.GONE);
                }else{
                    tv_7.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getDcdy().length()>2){
                        tv_7.setText("···");
                    }else
                        tv_7.setText(zhoubianBean.getDcdy());
                }
                // 失信人
                if("0".equals(zhoubianBean.getSxr())||"".equals(zhoubianBean.getSxr())){
                    tv_8.setVisibility(View.GONE);
                }else{
                    tv_8.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getSxr().length()>2){
                        tv_8.setText("···");
                    }else
                        tv_8.setText(zhoubianBean.getSxr());
                }
                // 被执行人
                if("0".equals(zhoubianBean.getBzxr())||"".equals(zhoubianBean.getBzxr())){
                    tv_9.setVisibility(View.GONE);
                }else{
                    tv_9.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getBzxr().length()>2){
                        tv_9.setText("···");
                    }else
                        tv_9.setText(zhoubianBean.getBzxr());
                }
                // 个人风险
                if("0".equals(zhoubianBean.getRfx())||"".equals(zhoubianBean.getRfx())){
                    tv_10.setVisibility(View.GONE);
                }else{
                    tv_10.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getRfx().length()>2){
                        tv_10.setText("···");
                    }else
                        tv_10.setText(zhoubianBean.getRfx());
                }
//        // 股票行情
//        if("0".equals(zhoubianBean.())){
//            tv_12.setVisibility(View.GONE);
//        }else{
//            tv_12.setVisibility(View.VISIBLE);
//            tv_12.setText(zhoubianBean.getGpfh());
//        }
                // 股票分红
                if("0".equals(zhoubianBean.getGpfh())||"".equals(zhoubianBean.getGpfh())){
                    tv_14.setVisibility(View.GONE);
                }else{
                    tv_14.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getGpfh().length()>2){
                        tv_14.setText("···");
                    }else
                        tv_14.setText(zhoubianBean.getGpfh());
                }
                // 债券信息
                if("0".equals(zhoubianBean.getZjxx())||"".equals(zhoubianBean.getZjxx())){
                    tv_15.setVisibility(View.GONE);
                }else{
                    tv_15.setVisibility(View.VISIBLE);
                    if(zhoubianBean.getZjxx().length()>2){
                        tv_15.setText("···");
                    }else
                        tv_15.setText(zhoubianBean.getZjxx());
                }
            }

        }catch(Exception e){
            LogUtils.e("sfz",e.toString());
        }



    }

    @OnClick({R.id.ll_item1,R.id.ll_item2,R.id.ll_item3,R.id.ll_item4,R.id.ll_item5,R.id.ll_item6,R.id.ll_item7,R.id.ll_item8,R.id.ll_item9,R.id.ll_item10,R.id.ll_item11,R.id.ll_item12,R.id.ll_item13,R.id.ll_item14,R.id.ll_item15})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.ll_item1:
                if(bean!=null){
                    if("0".equals(bean.getXzrf())||"".equals(bean.getXzrf())){
                        ToastUtils.showToast(getActivity(),"无数据");
                    }else{
                        startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                .putExtra("title","行政处罚")
                                .putExtra("type",Constants.EyeCheck_XZRF_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(),"无数据");
                }


                break;
            // 严重违法
            case R.id.ll_item2:
                if(bean!=null) {
                    if ("0".equals(bean.getYzwf())||"".equals(bean.getYzwf())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                .putExtra("title","严重违法")
                                .putExtra("type",Constants.EyeCheck_YZWF_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(),"无数据");
                }

                break;
            // 股权出质
            case R.id.ll_item3:
//                ToastUtils.showToast(getActivity(),"暂无数据");
                if(bean!=null) {
                    if ("0".equals(bean.getGqcz())||"".equals(bean.getGqcz())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                .putExtra("title","股权出质")
                                .putExtra("type",Constants.EyeCheck_GQCZ_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(),"无数据");
                }

                break;
            case R.id.ll_item4:
                if(bean!=null) {
                    if ("0".equals(bean.getGbbd())||"".equals(bean.getGbbd())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                .putExtra("title","股本变动")
                                .putExtra("type",Constants.EyeCheck_GBBD_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            // 企业风险
            case R.id.ll_item5:
//                ToastUtils.showToast(getActivity(),"暂无数据");
                if(bean!=null){
                    startActivity(new Intent().setClass(getActivity(), QyfxActivity.class)
                            .putExtra("title","企业风险")
                            .putExtra("type",Constants.EyeCheck_QYFX_TYPE)
                            .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                            .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                            .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            // 经营异常
            case R.id.ll_item6:
                if(bean!=null) {
                    if ("0".equals(bean.getJyrc())||"".equals(bean.getJyrc())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                .putExtra("title","经营异常")
                                .putExtra("type",Constants.EyeCheck_JYYC_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            // 动产抵押
            case R.id.ll_item7:
//                ToastUtils.showToast(getActivity(),"暂无数据");
                if(bean!=null) {
                    if ("0".equals(bean.getDcdy())||"".equals(bean.getDcdy())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                .putExtra("title","动产抵押")
                                .putExtra("type",Constants.EyeCheck_DCDY_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            // 失信人
            case R.id.ll_item8:
                if(bean!=null) {
                    if ("0".equals(bean.getSxr())||"".equals(bean.getSxr())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                .putExtra("title","失信人")
                                .putExtra("type",Constants.EyeCheck_SXR_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            case R.id.ll_item9:
                if(bean!=null) {
                    if ("0".equals(bean.getBzxr())||"".equals(bean.getBzxr())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                .putExtra("title","被执行人")
                                .putExtra("type",Constants.EyeCheck_BZXR_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }


                break;
            case R.id.ll_item10:
//                ToastUtils.showToast(getActivity(),"暂无数据");
                        if(bean!=null) {
                            if ("0".equals(bean.getRfx())||"".equals(bean.getRfx())) {
                                ToastUtils.showToast(getActivity(), "无数据");
                            } else {
                                startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                .putExtra("title","个人风险")
                                .putExtra("type",Constants.EyeCheck_RFX_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                            ToastUtils.showToast(getActivity(), "无数据");
                        }

                break;
            case R.id.ll_item11:
                if(bean!=null){
                    startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                            .putExtra("title","股本结构")
                            .putExtra("type",Constants.EyeCheck_GBJG_TYPE)
                            .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                            .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                            .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            case R.id.ll_item12:
                if(bean!=null){
                    startActivity(new Intent().setClass(getActivity(), GphqDetailActivity.class)
                            .putExtra("title","股票行情")
                            .putExtra("type",Constants.EyeCheck_GPHQ_TYPE)
                            .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                            .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                            .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }


                break;
            // 股票简介
            case R.id.ll_item13:
                ToastUtils.showToast(getActivity(),"暂无数据");
                break;
            case R.id.ll_item14:
                if(bean!=null) {
                    if ("0".equals(bean.getGpfh())||"".equals(bean.getGpfh())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                .putExtra("title","股票分红")
                                .putExtra("type",Constants.EyeCheck_GPFH_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }

                break;
            case R.id.ll_item15:
                if(bean!=null) {
                    if ("0".equals(bean.getZjxx())||"".equals(bean.getZjxx())) {
                        ToastUtils.showToast(getActivity(), "无数据");
                    } else {
                        startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                .putExtra("title","债券信息")
                                .putExtra("type",Constants.EyeCheck_ZJXX_TYPE)
                                .putExtra("proId",((ZhoubianActivity)getActivity()).getMySelectCompany().getProId())
                                .putExtra("cmpanyType",((ZhoubianActivity)getActivity()).getMySelectCompany().getType())
                                .putExtra("companyId",((ZhoubianActivity)getActivity()).getMySelectCompany().getId()));
                    }
                }else{
                    ToastUtils.showToast(getActivity(), "无数据");
                }


                break;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder1 = ButterKnife.bind(this, rootView);

        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder1.unbind();
    }



    @Override
    public void getCurrentPos(JigouBean.Company company) {

        if(company!=null){
            LogUtils.e("sfz","风险:"+company.getName());
            LogUtils.e("sfz","风险type:"+company.getType());
            eyeCheckCount(AppUtil.getUserId(getActivity()),company.getId());
        }else{
            bean = null;
            LogUtils.e("sfz","风险:企业为空");
            showview(null);
        }

    }
}
